""" This is the zone for Packed Object process
    ID combination is not supported in this version except for 17+10 (AI)
"""
import re
class IDInfo:
    
    
    
    def __init__(self):
        self.relativeOID = ''
        self.idValue = ''
        self.idString = ''
        self.formatStr = ''
        
    def getRelativeOID(self):
        return self.relativeOID
    
    def getIDValue(self):
        return self.idValue
    
    def getOIDString(self, is_converted = True):
        if is_converted == False:
            return self.idString        
        
        if '%' in self.idString:
            parts = self.idString.split('%x')
            start = int(parts[1].split('-')[0].strip(), 16) - 48
            end = int(parts[1].split('-')[1].strip().strip(')'), 16) - 48
            
            value_array = list()
            for i in range(end - start):
                current_value = parts[0].strip().strip('(') + str(start + i)
                value_array.append(current_value)
            
            return value_array
        
        return [self.idString]
    
    def getSplitedOIDString(self):
        pattern = '\((.+?)\)'
        re_obj = re.compile(pattern)
        return_splited_value = re_obj.findall(self.idString)
        return return_splited_value
    

    def getSplitedOIDStringByIndex(self, index):
        splited_value = self.getSplitedOIDString()
        return splited_value[index]
    
    def isCombinationOID(self):
        pattern = '\((.+?)\)'
        re_obj = re.compile(pattern)
        return_splited_value = re_obj.findall(self.formatStr)                
        if len(return_splited_value) != 0:
            return True
        return False
    
    def getFormatStr(self):
        return self.formatStr
    
    def getOIDStringByIndex(self, index):
        """This method is used for combination OID
        """        
        pattern = '\((.+?)\)'
        re_obj = re.compile(pattern)
        return_splited_value = re_obj.findall(self.idString)                
        return return_splited_value[index]
        
    def getSplitedFormatStr(self):
        pattern = '\((.+?)\)'
        re_obj = re.compile(pattern)
        return_splited_value = re_obj.findall(self.formatStr)                
        if len(return_splited_value) != 0:
            return return_splited_value        
        return_splited_value = re.split("\s", self.formatStr)
        if len(return_splited_value) != 0:
            return return_splited_value
        return self.formatStr        
        
#        for split_value in re_obj.findall(self.formatStr):
#            print split_value
#            print "--"
#           
#            print "+++++++++++"
            
    def setRelativeOID(self, rOID=''):
        self.relativeID = rOID
        
    def setIDValue(self, idValue=''):
        self.idValue = idValue
        
    def setOIDString(self, idStr=''):
        self.idString = idStr
        
    def setFormatStr(self, formatStr=''):
        self.formatStr = formatStr
    